package com.wl.common;

import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.util.HashMap;

import static com.wl.common.FileButton.*;
import static com.wl.config.SettingConfig.readYamlFile;

//窗口创建帮助类
public final class UIHelper {
  private static final String SPACING = "spacing";
  private static final String WIDE = "wide";
  private static final String HIGH = "high";

  public static ListView<String> fileListView;

  private UIHelper() {
    throw new UnsupportedOperationException("你想实例化一个窗口类？你打算重写它的样式？？？？");
  }

  public static void setupPrimaryStage(Stage primaryStage) {
    //读取yaml获取间距(spacing)、高(high)、宽(wide)
    HashMap<String,Integer> allBoxView = readYamlFile("all_box_view", HashMap.class);

    // 创建文件上传按钮
    VBox vbox = getvBox(primaryStage);
    //创建整体视图
    HBox root = new HBox(vbox, getFileListView());
    root.setSpacing(allBoxView.get(SPACING));
    Scene scene = new Scene(root, allBoxView.get(WIDE), allBoxView.get(HIGH));
    primaryStage.setScene(scene);
    primaryStage.setTitle("万能文档转换 v0.1");
    primaryStage.show();
  }

  //获取窗口设置窗口
  private static VBox getvBox(Stage primaryStage) {
    //创建下拉框
    ComboBox<String> formatComboBox = getFileDropDownButton("file_types");

    //获取文件转换按钮
    Button fileConvertButton = getFileConvertButton(primaryStage);

    //获取上传按钮
    Button fileUploaderButton = getFileUploaderButton(primaryStage);

    Label label = new Label("选择你需要转换成的格式:");
    VBox vbox = new VBox(label, formatComboBox, fileUploaderButton, fileConvertButton);


    //读取yaml获取间距(spacing)、高(high)、宽(wide)
    HashMap<String,Integer> boxView = readYamlFile("left_box_view", HashMap.class);

    vbox.setSpacing(boxView.get(SPACING));
    vbox.setPrefSize(boxView.get(WIDE), boxView.get(HIGH));
    return vbox;
  }

  // 获取文件列表视图
  private static VBox getFileListView() {
    HashMap<String,Integer> fileListViewSiz = readYamlFile("file_list_view", HashMap.class);
    fileListView = new ListView<>();
    fileListView.setPrefWidth(fileListViewSiz.get(WIDE));
    fileListView.setPrefHeight(fileListViewSiz.get(HIGH));
    VBox vbox = new VBox(new Label("上传的文件列表:"), fileListView);
    vbox.setSpacing(fileListViewSiz.get(SPACING));
    return vbox;
  }
}


